package com.proj.hot.activity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

import com.proj.hot.R;
import com.proj.hot.widget.CommonGallery;

/**
 * 暂时还没用到这个界面
 */
public class MainActivity extends BaseActivity {

    private final String TAG = getClass().getSimpleName();


    private CommonGallery commonGallery;

//    private int[] imageIds = new int[]{
//            R.drawable.timg1,R.drawable.timg2,R.drawable.timg3,R.drawable.timg4,R.drawable.timg5,R.drawable.timg6,
//            R.drawable.timg7,R.drawable.timg8,R.drawable.timg9,R.drawable.timg10,R.drawable.timg11,R.drawable.timg12,
//            R.drawable.timg13,R.drawable.timg14,R.drawable.timg15,R.drawable.timg16,R.drawable.timg17,R.drawable.timg18,
//            R.drawable.timg19,R.drawable.timg20,R.drawable.timg21};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        commonGallery = (CommonGallery)this.findViewById(R.id.gallery);
        BaseAdapter adapter = new BaseAdapter() {
            @Override
            public int getCount() {
               // return imageIds.length;
                return 0;
            }

            @Override
            public Object getItem(int i) {
                return i;
            }

            @Override
            public long getItemId(int i) {
                return i;
            }

            @Override
            public View getView(int i, View view, ViewGroup viewGroup) {
                ImageView imageView = new ImageView(MainActivity.this);
               // imageView.setImageResource(imageIds[i]);
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                imageView.setLayoutParams(new Gallery.LayoutParams(250,500));
                //TypedArray typedArray = obtainStyledAttributes(R.);

                return imageView;
            }

        };
        commonGallery.setAdapter(adapter);
        commonGallery.setSelection(5);

    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            return true;
        }
        else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            return true;
        }
        else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT
                && event.getAction() == KeyEvent.ACTION_DOWN) {

            return true;
        }
        else if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
